package com.module.codeBind.dao;

import java.util.Date;

import org.hibernate.Session;

import base.common.CUDEnum;
import base.dao.GenericHibernateDao;
import base.util.BeanChangeUtil;

import com.module.codeBind.common.CodeBindConstant;
import com.module.codeBind.vo.BatchCode;
import com.module.codeBind.vo.BatchCodeSyn;

public class BatchCodeSynDao extends GenericHibernateDao<BatchCodeSyn,Long> implements CodeBindConstant{
	private static BatchCodeSynDao dao = new BatchCodeSynDao();
	private BatchCodeSynDao(){}
	public static BatchCodeSynDao getInstance(){
		return dao;
	}
	/**
	 * 新增批次表操作记录（增量表）
	 * @param session
	 * @param batchCodeSyn
	 * @return
	 */
	 public boolean saveBatchCodeSyn(Session session,BatchCodeSyn batchCodeSyn){
	    	boolean result=false;
	    	try{    		
	    		batchCodeSyn.setIssysc("1");
	    		batchCodeSyn.setSyscTime(new Date());
	        	result = this.save(session, batchCodeSyn);
	    	}catch(Exception e) {
	    		e.printStackTrace();
			}
	    	return result;
	    }
	 /**
	  * 修改批次表（新增增量表操作记录）
	  * @param session
	  * @param beanEld
	  * @param bean
	  * @return
	  */
	 public boolean updateBatchCodeSyn(Session session,BatchCode beanEld,BatchCode bean){
	    	boolean result = false;
	    	try{
	    		BatchCodeSyn batchCodeSyn = null;
	    		batchCodeSyn = (BatchCodeSyn) BeanChangeUtil.findDiff(beanEld, bean, BatchCodeSyn.class);//对比数据，并构建目标对象
	    		batchCodeSyn.setSyscStatus(CUDEnum.U.toString());
	    		batchCodeSyn.setId(bean.getId());
	    		result = saveBatchCodeSyn(session, batchCodeSyn);
	    	}catch(Exception e){
	    		e.printStackTrace();
	    	}
	    	return result;
	    }
}
